package com.netscenery.yang.model;



import java.util.*;



import org.jdom2.Attribute;
import org.jdom2.Element;
import org.jdom2.Namespace;

import com.netscenery.util.ErrTag;
import com.netscenery.util.Link;
import com.netscenery.util.Unicode;
import com.netscenery.util.XMLTag;
import com.netscenery.yang.YangKeyword;
import com.netscenery.yang.YangStatement;
import com.netscenery.yang.designer.LeafFieldMap;
import com.netscenery.yang.designer.ListFieldMap;
import com.netscenery.yang.designer.MapInfo;
import com.netscenery.yang.designer.MethodInfo;

import com.netscenery.yang.designer.Parameter;
import com.netscenery.yang.parser.YangParserException;


public abstract class Module extends ModelElement{
	private String description;
	private String organization;
	private String contact;
	private String reference;
	private ArrayList<Include> includes;
	private ArrayList<Import> imports;
	private Link<Revision> revisions;
	private ArrayList<Extension> extensions;
	private ArrayList<Typedef> typedefs;
	private DataDefEntity dataDefs;
	//private Link<DataDefElement> dataDefs;
	private ArrayList<Feature> features;
	//private ArrayList<Anyxml> anyxmls;
	private ArrayList<Augment> augments;
	//private ArrayList<Uses> usess;
	private ArrayList<Grouping> groupings;
	private ArrayList<Deviation> deviations;
	private ArrayList<Identity> identities;
	private ArrayList<Notification> notifications;
	private ArrayList<Rpc> rpcs;
	public String yangVersion = "1";

	public Module(Env env, String name) throws ModelException{
		super(env,name);
		dataDefs = new DataDefEntity(newSubEnv());
	}
	
/**
	 * @return the dataDefs
	 */
	public DataDefEntity getDataDefs() {
		return dataDefs;
	}

	/**
	 * @param dataDefs the dataDefs to set
	 */
	public void setDataDefs(DataDefEntity dataDefs) {
		this.dataDefs = dataDefs;
	}

	//	public boolean validateList(ArrayList list, Class clazz) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
//		if (null == list){
//			return false;
//		}
//		int size = list.size();
//		for (int i = 0; i < size; i++){
//			Object o = list.get(i);
//			if (null == o ){
//				continue;
//			}
//			Method validate = clazz.getMethod("validate");
//			if (null == validate){
//				return false;
//			}
//			Object ret = validate.invoke(o);
//			if(!(ret instanceof Boolean)){
//				return false;
//			}
//			Boolean bo = (Boolean)ret;
//			if(!bo.booleanValue()){
//				return false;
//			}
//		}
//		return true;
//	}
	/**
	 * ��֤�������÷���������֤ģ��ĺϷ��ԣ����ģ�鲻�Ϸ���
	 * ���ھ��棬����ڷ��ص�Validator���з�����ϸ�Ĵ���򾯸�
	 * ��Ϣ��
	 * @return Validator
     * @see com.netscenery.model.Validator
	 */
	public Validator validate(){
		Validator validator = new Validator();
		if (null != includes){
			if(null != ModelElement.checkNameConflict(includes)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"include",ErrorCode.CONFLICT_NAME));
			}
			int size = getIncludesNumber();
			for (int i = 0; i < size; i++){
				Include in = getInclude(i);
				if (null == in ){
					continue;
				}
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		if (null != imports){
			if(null != ModelElement.checkNameConflict(imports)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"import",ErrorCode.CONFLICT_NAME));
			}
			int size = getImportsNumber();
			for (int i = 0; i < size; i++){
				Import in = getImport(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}	
		
		if (null != revisions){
			if(null !=ModelElement.checkNameConflict(revisions)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"revision",ErrorCode.CONFLICT_NAME));
			}
			int size = getRevisionsNumber();
			for (int i = 0; i < size; i++){
				Revision in = getRevision(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}	
		
		if (null != extensions){
			if(null !=ModelElement.checkNameConflict(extensions)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"extension",ErrorCode.CONFLICT_NAME));
			}
			int size = getExtensionsNumber();
			for (int i = 0; i < size; i++){
				Extension in = getExtension(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		
		if (null != features){
			if(null !=ModelElement.checkNameConflict(features)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"feature",ErrorCode.CONFLICT_NAME));
			}
			int size = getFeaturesNumber();
			for (int i = 0; i < size; i++){
				Feature in = getFeature(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		
		if (null != identities){
			if(null !=ModelElement.checkNameConflict(identities)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"identity",ErrorCode.CONFLICT_NAME));
			}
			int size = getIdentitiesNumber();
			for (int i = 0; i < size; i++){
				Identity in = getIdentity(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		
		if (null != typedefs){
			if(null !=ModelElement.checkNameConflict(typedefs)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"typedef",ErrorCode.CONFLICT_NAME));
			}
			int size = getTypedefsNumber();
			for (int i = 0; i < size; i++){
				Typedef in = getTypedef(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		if (null != groupings){
			if(null !=ModelElement.checkNameConflict(groupings)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"grouping",ErrorCode.CONFLICT_NAME));
			}
			int size = getGroupingsNumber();
			for (int i = 0; i < size; i++){
				Grouping in = getGrouping(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		
		if (null != dataDefs && 0 != dataDefs.getDataDefsNumber()){
			validator.copy(dataDefs.validate());
		}
		if (null != notifications){
			if(null !=ModelElement.checkNameConflict(notifications)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"notification",ErrorCode.CONFLICT_NAME));
			}
			int size = getNotificationsNumber();
			for (int i = 0; i < size; i++){
				Notification in = getNotification(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}

		if (null != augments){
			if(null != ModelElement.checkNameConflict(augments)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"augment",ErrorCode.CONFLICT_NAME));
			}
			int size = getAugmentsNumber();
			for (int i = 0; i < size; i++){
				Augment in = getAugment(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		if (null != deviations){
			if(null != ModelElement.checkNameConflict(deviations)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"deviation",ErrorCode.CONFLICT_NAME));
			}
			int size = getDeviationsNumber();
			for (int i = 0; i < size; i++){
				Deviation in = getDeviation(i);
				if (null == in ){
					continue;
				}
				
				Validator inv = in.validate();
				validator.copy(inv);
			}
		}
		if (!isNullString(this.contact)){
			if (Unicode.containChinese(this.contact)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"contact",ErrorCode.INVALID_CHARACTER));
			}
		}
		
		if (!isNullString(this.organization)){
			if (Unicode.containChinese(this.organization)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"organization",ErrorCode.INVALID_CHARACTER));
			}
		}
		if (!isNullString(this.description)){
			if (Unicode.containChinese(this.description)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"description",ErrorCode.INVALID_CHARACTER));
			}
		}
		
		if (!isNullString(this.reference)){
			if (Unicode.containChinese(this.reference)){
				validator.setIsValid(false);
				validator.addMsg(new Message(this,ErrTag.ERROR,"reference",ErrorCode.INVALID_CHARACTER));
			}
		}
		
		Validator sValidator = super.validate();
		validator.copy(sValidator);
		return validator;
	}

//	public ArrayList<Typedef> getTypedefs() {
//		return typedefs;
//	}
//
//	public void setTypedefs(ArrayList<Typedef> typedefs) {
//		this.typedefs = typedefs;
//	}
//
//	public Link<Node> getNodes() {
//		return nodes;
//	}
//
//	public void setNodes(Link<Node> nodes) {
//		this.nodes = nodes;
//	}
//	
//	
//	
//	/**
//	 * @return the extensions
//	 */
//	public ArrayList<Extension> getExtensions() {
//		return extensions;
//	}
//
//	/**
//	 * @param extensions the extensions to set
//	 */
//	public void setExtensions(ArrayList<Extension> extensions) {
//		this.extensions = extensions;
//	}

	/**
	 * ��ȡ��չ�ؼ��ֵ���Ŀ
	 * @return
	 * @see com.netscenery.model.Extension
	 */
	public int getExtensionsNumber(){
		if (null == this.extensions){
			return 0;
		}
		return this.extensions.size();
	}
	/**
	 * ���ָ������ƴ�����չ�ؼ���
	 * @param name
	 * @return
	 * @see com.netscenery.model.Extension
	 */
	public Extension createExtension(String name){
		if (null == name){
			return null;
		}
		
		return new Extension(newSubEnv(),name);
	}
	/**
	 * ���һ����չ�ؼ���
	 * @param n
	 * @return
	 * @see com.netscenery.model.Extension
	 */
	public boolean addExtension(Extension n){
		if(null == n){
			return false;
		}
		
		if (null == this.extensions){
			this.extensions = new ArrayList<Extension>(1);
		}
		if (null != this.getExtension(n.getName())){
			return false;
		}
		return this.extensions.add(n);
		

	}
	/**
	 * �����Ż�ȡ��չ�ؼ���
	 * @param index
	 * @return
	 * @see com.netscenery.model.Extension
	 */
	public Extension getExtension(int index){
		if (null == this.extensions){
			return null;
		}
		if (index >= this.extensions.size()){
			return null;
		}
		return this.extensions.get(index);
	}
	/**
	 * �����ƻ�ȡ��չ�ؼ���
	 * @param name
	 * @return
	 * @see com.netscenery.model.Extension
	 */
	public Extension getExtension(String name){
		if (null == this.extensions){
			return null;
		}
		int size = extensions.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Extension n = this.extensions.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return n;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ����չ�ؼ���
	 * @param index
	 * @return Extension
	 * @see com.netscenery.model.Extension
	 */
	public Extension removeExtension(int index){
		if (null == this.extensions){
			return null;
		}
		if (index >= this.extensions.size()){
			return null;
		}
		return this.extensions.remove(index);
	}
	/**
	 * ������ɾ����չ�ؼ���
	 * @param name
	 * @return Extension
	 * @see com.netscenery.model.Extension
	 */
	public Extension removeExtension(String name){
		if (null == this.extensions){
			return null;
		}
		int size = extensions.size();
		if (size <= 0){
			return null;
		}
		
		
		for (int i = 0; i < size; i++){
			Extension n = this.extensions.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return extensions.remove(i);
				}
			}
		}
		return null;
	}
	/**
	 * @param env
	 * ���û�������
	 * @see com.netscenery.model.Env
	 */
	public void setEnv(Env env){
		if (null == env){
			return;
		}
		env.setCurModule(this);
		super.setEnv(env);
	}

	/**
	 * ����ģ�����
	 * @param name
	 * @return boolean 
	 * ���Ǹ����setName����
	 * @see com.netscenery.model.ModelElement 
	 */
	public boolean setName(String name){
		
		if (null != env){
			if (null != env.getModule(name)){
				return false;
			}
		}
		return super.setName(name);

	}
	/**
	 * ��ȡģ�����
	 * @return String
	 */
	public String getName(){
		return this.name;
	}
	/**
	 * ��ȡ����
	 * @return String
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * ��������
	 * @param description
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * ��ȡ��֯���
	 * @return
	 */
	public String getOrganization() {
		return organization;
	}
	/**
	 * ������֯���
	 * @param organization
	 */
	public void setOrganization(String organization) {
		this.organization = organization;
	}
	/**
	 * ��ȡ��ϵ��ʽ
	 * @return
	 */
	public String getContact() {
		return contact;
	}
	/**
	 * ������ϵ��ʽ
	 * @param contact
	 */
	public void setContact(String contact) {
		this.contact = contact;
	}
	/**
	 * ��ȡ������Ϣ
	 * @return
	 */
	public String getReference() {
		return reference;
	}
	/**
	 * ����������Ϣ
	 * @param reference
	 */
	public void setReference(String reference) {
		this.reference = reference;
	}
	
	public Node createNode(String type,String nodeName) throws ModelException{
		if (null == dataDefs){
			return null;
		}
		return (Node) this.dataDefs.createDataDef(type, nodeName);
	}
	public Uses createUses(String name) throws ModelException{
		if (null == dataDefs){
			return null;
		}
		return (Uses) this.dataDefs.createDataDef(YangKeyword.USES.getKeyword(), name);
	}
	public boolean addNode(Node node){
		if (null == dataDefs){
			return false;
		}
		
		return dataDefs.addDataDef(node);
	}
	
	public boolean addUses(Uses uses){
		if (null == dataDefs){
			return false;
		}
	
		return dataDefs.addDataDef(uses);
	}
	
	public DataDefElement getDataDef(int i){
		if (null == dataDefs){
			return null;
		}
	
		return dataDefs.getDataDef(i);
	}
	
	public DataDefElement removeDataDef(int i){
		if (null == dataDefs){
			return null;
		}
	
		return dataDefs.removeDataDef(i);
	}
	
	public int getDataDefsNumber(){
		if (null == dataDefs){
			return 0;
		}
	
		return dataDefs.getDataDefsNumber();
	}
	
	/**
	 * ���ָ����ģ����һ�������
	 * ʹ�ô˽ӿ�ǰӦ��ȷ������ģ��
	 * �Ѿ��������Ѽ��뵽����������
	 * @param moduleName
	 * @return Include
	 * @see com.netscenery.model.Include
	 */
	public Include createInclude(String moduleName){
		if (null == moduleName){
			return null;
		}
		
		return  new Include(newSubEnv(),moduleName);
	}

	/**
	 *���һ������Ϣ
	 * @param include
	 * @return boolean
	 * @see com.netscenery.model.Include
	 */
	public boolean addInclude(Include include){
		if (null == include){
			return false;
		}
		
		if (null == this.includes){
			this.includes = new ArrayList<Include>(1);
		}
		this.includes.add(include);
		Env env = this.getEnv();
		env.addSubModule(include.getInclude());
		return true;
	}
	/**
	 * �����Ż�ȡ����Ϣ
	 * @param index
	 * @return Include
	 * @see com.netscenery.model.Include
	 */
	public Include getInclude(int index){
		if (null == this.includes){
			return null;
		}
		if (index >= this.includes.size()){
			return null;
		}
		return this.includes.get(index);
	}
	/**
	 * ������ɾ�����Ϣ
	 * @param index
	 * @return
	 * @see com.netscenery.model.Include
	 */
	public Include removeInclude(int index){
		if (null == this.includes){
			return null;
		}
		if (index >= this.includes.size()){
			return null;
		}
		return this.includes.remove(index);
	}
	/**
	 * ������ɾ�����Ϣ
	 * @param name �����ģ�����
	 * @return
	 * @see com.netscenery.model.Include
	 */
	public Include removeInclude(String name){

		int size = getIncludesNumber();
		if (0 == size){
			return null;
		}
		
		for (int i = 0; i < size; i++) {
			Include in = getInclude(i);
			if (null != in ){
				if (in.getName().equals(name)){
					return removeInclude(i);
				}
			}
		}
		return null;
	}
	/**
	 * ��ȡ��ĸ���
	 * 
	 * @return
	 * @see com.netscenery.model.Include
	 */
	public int getIncludesNumber(){
		if (null == this.includes){
			return 0;
		}
		return this.includes.size();
	}
	/**
	 * ���ģ����������Ϣ��ʹ�ô˽ӿ�ǰӦ��ȷ��
	 * �������ģ���Ѵ��ڣ����Ѽ��뵽����������
	 * @param moduleName �����ģ����
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public Import createImport(String moduleName){
		if (null == moduleName){
			return null;
		}
		
		return  Import.create(newSubEnv(),moduleName);
	}
	/**
	 * ���һ��������Ϣ
	 * @param importElement
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public boolean addImport(Import importElement){
		if(null == importElement){
			return false;
		}
		
		if (null == this.imports){
			this.imports = new ArrayList<Import>(1);
		}
		if (null != this.getImportByName(importElement.getName())){
			return false;
		}
		
		if (null != this.getImport(importElement.getPrefix())){
			return false;
		}
		
		this.imports.add(importElement);
		Env env = this.getEnv();
		env.addMainModule(importElement.getImportedModule());
		env.addPrefix(importElement.getPrefix());
		return true;
	}
	public Import getImportByName(String name){
		if (null == this.imports){
			return null;
		}
		int size = getImportsNumber();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Import imp = this.imports.get(i);
			if (null != imp){
				if (imp.getName().equals(name)){
					return imp;
				}
			}
		}
		return null;
	}
	/**
	 * �����Ż�ȡ������Ϣ
	 * 
	 * @param index
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public Import getImport(int index){
		if (null == this.imports){
			return null;
		}
		if (index >= this.imports.size()){
			return null;
		}
		return this.imports.get(index);
	}
	/**
	 * ���ǰ׺��ȡ������Ϣ
	 * @param prefix
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public Import getImport(String prefix){
		if (null == this.imports){
			return null;
		}
		int size = getImportsNumber();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Import imp = this.imports.get(i);
			if (null != imp){
				if (imp.getPrefix().equals(prefix)){
					return imp;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ������Ϣ
	 * @param index
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public Import removeImport(int index){
		if (null == this.imports){
			return null;
		}
		if (index >= this.imports.size()){
			return null;
		}
		return this.imports.remove(index);
	}
	/**
	 * ������ɾ������Ϣ
	 * @param name
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public Import removeImport(String name){
		if (null == name){
			return null;
		}
		
		int size = getImportsNumber();
		if (0 == size){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Import imp = getImport(i);
			if (null != imp){
				if (imp.getName().equals(name)){
					return removeImport(i);
				}
			}
		}
		
		return null;
	}
	
	/**
	 * ��ȡ�������Ŀ��
	 * @return
	 * @see com.netscenery.model.Import
	 */
	public int getImportsNumber(){
		if (null == this.imports){
			return 0;
		}
		return this.imports.size();
	}
	/**
	 * ���ָ������ƴ���һ���汾��������Ʊ�����
	 * YYYY-MM-DD����ʽ
	 * @param name
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	public Revision createRevision(String name){
		Revision revision = new Revision(name);
		revision.setEnv(newSubEnv());
		return revision;
	}
	/**
	 * ���һ���汾
	 * @param revision
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	
	public boolean addRevision(Revision revision){
		if (null == revision){
			return false;
		}
		if (null == this.revisions){
			this.revisions = new Link<Revision>(Link.SortOrder.DESCEND);
		}
		if (null != getRevision(revision.getName())){
			return false;
		}
		return this.revisions.insert(revision);
		
	}
	
	public Revision getCurRevision(){
		return getRevision(0);
	}
	
	public String getCurRevisionDate(){
		Revision revision = getCurRevision();
		if (null == revision){
			return null;
		}
		
		return revision.getName();
	}
	/**
	 * �����Ż�ȡ�汾��Ϣ
	 * @param index
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	public Revision getRevision(int index){
		if (null == this.revisions){
			return null;
		}
		if (index >= this.revisions.size()){
			return null;
		}
		
		return this.revisions.get(index);
	}
	/**
	 * �����ƻ�ȡ�汾��Ϣ
	 * @param name
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	public Revision getRevision(String name){
		if (null == this.revisions){
			return null;
		}
		int size = revisions.size();
		for(int i = 0; i < size; i++){
			Revision rev = revisions.get(i);
			if (null == rev){
				continue;
			}
			
			if (rev.getName().equals(name)){
				return rev;
			}
		}
		
		return null;
	}
	/**
	 * ������ɾ��汾��Ϣ
	 * @param name
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	public Revision removeRevision(String name){
		if (null == this.revisions){
			return null;
		}
		int size = revisions.size();
		for(int i = 0; i < size; i++){
			Revision rev = revisions.get(i);
			if (null == rev){
				continue;
			}
			
			if (rev.getName().equals(name)){
				return revisions.remove(i);
			}
		}
		
		return null;
	}
	/**
	 * ������ɾ��汾��Ϣ
	 * @param index
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	public Revision removeRevision(int index){
		if (null == this.revisions){
			return null;
		}
		if (index >= this.revisions.size()){
			return null;
		}
		return this.revisions.remove(index);
	}
	/**
	 * ��ȡ�汾��Ŀ��
	 * @return
	 * @see com.netscenery.model.Revision
	 */
	public int getRevisionsNumber(){
		if (null == this.revisions){
			return 0;
		}
		return this.revisions.size();
	}
	/**
	 * �����ƴ���һ��typedef
	 * @param name
	 * @return
	 * @see com.netscenery.model.Typedef
	 */
	public Typedef createTypedef(String name){
		if (null == name){
			return null;
		}
		
		return new Typedef(newSubEnv(),name);
	}
	/**
	 * ���һ��typedef
	 * @param def
	 * @return
	 * @see com.netscenery.model.Typedef
	 */
	public boolean addTypedef(Typedef def){
		if(null == def){
			return false;
		}
		
		if (null == this.typedefs){
			this.typedefs = new ArrayList<Typedef>(1);
		}
		this.typedefs.add(def);
		Env env = this.getEnv();
		env.addDerivedType(def);
		return true;
	}
	/**
	 * �����Ż�ȡtypedef
	 * @param index
	 * @return
	 * @see com.netscenery.model.Typedef
	 */
	public Typedef getTypedef(int index){
		if (null == this.typedefs){
			return null;
		}
		if (index >= this.typedefs.size()){
			return null;
		}
		return this.typedefs.get(index);
	}
	/**
	 * ���typedef��ƻ�ȡtypedef
	 * @param defName
	 * @return
	 * @see com.netscenery.model.Typedef
	 */
	public Typedef getTypedef(String defName){
		if (null == this.typedefs){
			return null;
		}
		int size = typedefs.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Typedef def = this.typedefs.get(i);
			if (null != def){
				if (def.getName().equals(defName)){
					return def;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ��typedef
	 * @param index
	 * @return
	 * @see com.netscenery.model.Typedef
	 */
	public Typedef removeTypedef(int index){
		if (null == this.typedefs){
			return null;
		}
		if (index >= this.typedefs.size()){
			return null;
		}
		return this.typedefs.remove(index);
	}
	/**
	 * ������ɾ��typedef
	 * @param defName
	 * @return
	 */
	public Typedef removeTypedef(String defName){
		if (null == this.typedefs){
			return null;
		}
		int size = typedefs.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Typedef def = this.typedefs.get(i);
			if (null != def){
				if (def.getName().equals(defName)){
					return typedefs.remove(i);
				}
			}
		}
		return null;
	}
	/**
	 * ��ȡtypedef�ĸ���
	 * @return
	 */
	public int getTypedefsNumber(){
		if (null == this.typedefs){
			return 0;
		}
		return this.typedefs.size();
	}


	
	/**
	 * ��ȡ���Ը���
	 * @return
	 */
	public int getFeaturesNumber(){
		if (null == features){
			return 0;
		}
		
		return features.size();
	}
	/**
	 * ���ָ����ƴ�������
	 * @param name
	 * @return
	 */
	public Feature createFeature(String name){
		if (null == name){
			return null;
		}
		
		return new Feature(newSubEnv(),name);
	}
	/**
	 * ���һ������
	 * @param feature
	 * @return
	 */
	public boolean addFeature(Feature feature){
		if (null == feature){
			return false;
		}
		
		if (null == features){
			features = new ArrayList<Feature>(1);
		}
		
		if (null != getFeature(feature.getName())){
			return false;
		}
		
		return features.add(feature);
		
	}
	
	/**
	 * @return the features
	 */
	public ArrayList<Feature> getFeatures() {
		return features;
	}

	/**
	 * ��ȡ��ǰ���õ���������б?��ʱ�᷵�ص�ǰģ�顢
	 * ��ģ��͵���ģ���Ѷ�����������
	 * 
	 * @return
	 */
	public ArrayList<String> getAvailableFeatureNames(){
		ArrayList<String> features = null;
		
		Module m = env.getCurModule();
		if (null == m){
			return null;
		}
		
		if (0 != m.getFeaturesNumber()){		
			if (null == features){
				features = new ArrayList<String>(1);
			}
			
			for (int i = 0;i < m.getFeaturesNumber();i++){
				Feature f = m.getFeature(i);
				if (null == f){
					continue;
				}
				
				features.add(f.getName());
			}
			
		}
		
		//���������ģ�����Ƿ����features
		if(0 != m.getImportsNumber()){
			int size = m.getImportsNumber();
			for (int i = 0; i < size; i++){
				Import imp = m.getImport(i);
				if (null == imp){
					continue;
				}
				
				MainModule mm = imp.getImportedModule();
				
				if (mm == null){
					continue;
				}
				if (0 != mm.getFeaturesNumber()){		
					if (null == features){
						features = new ArrayList<String>(1);
					}
					for (int j = 0;j < mm.getFeaturesNumber();j++){
						Feature f = mm.getFeature(j);
						if (null == f){
							continue;
						}
						String name = imp.getPrefix() + ":" + f.getName();
						features.add(name);
					}
				}
				
			}
		}
		
		//�������ģ�����Ƿ����features
		if(0 != m.getIncludesNumber()){
			int size = m.getIncludesNumber();
			for (int i = 0; i < size; i++){
				Include inc = m.getInclude(i);
				if (null == inc){
					continue;
				}
				
				SubModule sm = inc.getInclude();
				
				if (sm == null){
					continue;
				}
				if (0 != sm.getFeaturesNumber()){		
					if (null == features){
						features = new ArrayList<String>(1);
					}
					for (int j = 0;j < sm.getFeaturesNumber();j++){
						Feature f = sm.getFeature(j);
						if (null == f){
							continue;
						}
						
						features.add(f.getName());
					}
				}
				
			}
		}
		
		return features;
		
	}
	/**
	 * ��ȡ��ǰ���õ������б?��ʱ�᷵�ص�ǰģ�顢�����ģ���
	 * ����ģ��Ķ���������б�
	 * @return
	 */
	public ArrayList<Feature> getAvailableFeatures(){
		ArrayList<Feature> features = null;
		
		Module m = env.getCurModule();
		if (null == m){
			return null;
		}
		
		if (0 != m.getFeaturesNumber()){		
			if (null == features){
				features = new ArrayList<Feature>(1);
			}
			features.addAll(m.getFeatures());
		}
		
		//���������ģ�����Ƿ����features
		if(0 != m.getImportsNumber()){
			int size = m.getImportsNumber();
			for (int i = 0; i < size; i++){
				Import imp = m.getImport(i);
				if (null == imp){
					continue;
				}
				
				MainModule mm = imp.getImportedModule();
				
				if (mm == null){
					continue;
				}
				if (0 != mm.getFeaturesNumber()){		
					if (null == features){
						features = new ArrayList<Feature>(1);
					}
					features.addAll(mm.getFeatures());
				}
				
			}
		}
		
		//���������ģ�����Ƿ����features
		if(0 != m.getIncludesNumber()){
			int size = m.getIncludesNumber();
			for (int i = 0; i < size; i++){
				Include inc = m.getInclude(i);
				if (null == inc){
					continue;
				}
				
				SubModule sm = inc.getInclude();
				
				if (sm == null){
					continue;
				}
				if (0 != sm.getFeaturesNumber()){		
					if (null == features){
						features = new ArrayList<Feature>(1);
					}
					features.addAll(sm.getFeatures());
				}
				
			}
		}
		
		return features;
	}

	/**
	 * �����ƻ�ȡ����
	 * @param name
	 * @return
	 */
	public Feature getFeature(String name){
		if (null == name){
			return null;
		}
		
		if (null == features){
			return null;
		}
		
		int size = features.size();
		
		for (int i = 0; i < size; i++){
			Feature f = features.get(i);
			if (f.getName().equals(name)){
				return f;
			}
		}
		
		return null;
		
	}
	/**
	 * �����Ż������
	 * @param index
	 * @return
	 */
	public Feature getFeature(int index){
		if (null == features){
			return null;
		}
		
		return features.get(index);
	}
	/**
	 * ������ɾ������
	 * @param index
	 * @return
	 */
	public Feature removeFeature(int index){
		if (null == features){
			return null;
		}
		
		return features.remove(index);
	}
	/**
	 * ������ɾ������
	 * @param name
	 * @return
	 */
	public Feature removeFeature(String name){
		if (null == name){
			return null;
		}
		
		if (null == features){
			return null;
		}
		
		int size = features.size();
		
		for (int i = 0; i < size; i++){
			Feature f = features.get(i);
			if (f.getName().equals(name)){
				return features.remove(i);
			}
		}
		
		return null;
	}
	
	
	/**
	 * ��ȡʵ�����
	 * @return
	 */
	public int getIdentitiesNumber(){
		if (null == identities){
			return 0;
		}
		
		return identities.size();
	}
	/**
	 * ���ָ����ƴ���ʵ��
	 * @param name
	 * @return
	 * @throws ModelException 
	 */
	public Identity createIdentity(String name) throws ModelException{
		if (null == name){
			return null;
		}
		
		return new Identity(newSubEnv(),name);
	}
	/**
	 * ���һ��ʵ��
	 * @param identity
	 * @return
	 */
	public boolean addIdentity(Identity identity){
		if (null == identity){
			return false;
		}
		
		if (null == identities){
			identities = new ArrayList<Identity>(1);
		}
		
		if (null != getIdentity(identity.getName())){
			return false;
		}
		
		return identities.add(identity);
		
	}
	
	/**
	 * @return the identities
	 */
	public ArrayList<Identity> getIdentities() {
		return identities;
	}

	/**
	 * ��ȡ��ǰ���õ�ʵ������б?��ʱ�᷵�ص�ǰģ�顢
	 * ��ģ��͵���ģ���Ѷ����ʵ�����
	 * 
	 * @return
	 */
	public ArrayList<String> getAvailableIdentityNames(){
		ArrayList<String> identities = null;
		
		Module m = env.getCurModule();
		if (null == m){
			return null;
		}
		
		if (0 != m.getFeaturesNumber()){		
			if (null == identities){
				identities = new ArrayList<String>(1);
			}
			
			for (int i = 0;i < m.getIdentitiesNumber();i++){
				Identity f = m.getIdentity(i);
				if (null == f){
					continue;
				}
				
				identities.add(f.getName());
			}
			
		}
		
		//���������ģ�����Ƿ����features
		if(0 != m.getImportsNumber()){
			int size = m.getImportsNumber();
			for (int i = 0; i < size; i++){
				Import imp = m.getImport(i);
				if (null == imp){
					continue;
				}
				
				MainModule mm = imp.getImportedModule();
				
				if (mm == null){
					continue;
				}
				if (0 != mm.getFeaturesNumber()){		
					if (null == identities){
						identities = new ArrayList<String>(1);
					}
					for (int j = 0;j < mm.getFeaturesNumber();j++){
						Identity f = mm.getIdentity(j);
						if (null == f){
							continue;
						}
						String name = imp.getPrefix() + ":" + f.getName();
						identities.add(name);
					}
				}
				
			}
		}
		
		//�������ģ�����Ƿ����features
		if(0 != m.getIncludesNumber()){
			int size = m.getIncludesNumber();
			for (int i = 0; i < size; i++){
				Include inc = m.getInclude(i);
				if (null == inc){
					continue;
				}
				
				SubModule sm = inc.getInclude();
				
				if (sm == null){
					continue;
				}
				if (0 != sm.getFeaturesNumber()){		
					if (null == identities){
						identities = new ArrayList<String>(1);
					}
					for (int j = 0;j < sm.getFeaturesNumber();j++){
						Identity f = sm.getIdentity(j);
						if (null == f){
							continue;
						}
						
						identities.add(f.getName());
					}
				}
				
			}
		}
		
		return identities;
		
	}
	/**
	 * ��ȡ��ǰ���õ�ʵ���б?��ʱ�᷵�ص�ǰģ�顢�����ģ���
	 * ����ģ��Ķ����ʵ���б�
	 * @return
	 */
	public ArrayList<Identity> getAvailableIdentities(){
		ArrayList<Identity> identities = null;
		
		Module m = env.getCurModule();
		if (null == m){
			return null;
		}
		
		if (0 != m.getIdentitiesNumber()){		
			if (null == identities){
				identities = new ArrayList<Identity>(1);
			}
			identities.addAll(m.getIdentities());
		}
		
		//���������ģ�����Ƿ����features
		if(0 != m.getImportsNumber()){
			int size = m.getImportsNumber();
			for (int i = 0; i < size; i++){
				Import imp = m.getImport(i);
				if (null == imp){
					continue;
				}
				
				MainModule mm = imp.getImportedModule();
				
				if (mm == null){
					continue;
				}
				if (0 != mm.getFeaturesNumber()){		
					if (null == identities){
						identities = new ArrayList<Identity>(1);
					}
					identities.addAll(mm.getIdentities());
				}
				
			}
		}
		
		//���������ģ�����Ƿ����features
		if(0 != m.getIncludesNumber()){
			int size = m.getIncludesNumber();
			for (int i = 0; i < size; i++){
				Include inc = m.getInclude(i);
				if (null == inc){
					continue;
				}
				
				SubModule sm = inc.getInclude();
				
				if (sm == null){
					continue;
				}
				if (0 != sm.getFeaturesNumber()){		
					if (null == identities){
						identities = new ArrayList<Identity>(1);
					}
					identities.addAll(sm.getIdentities());
				}
				
			}
		}
		
		return identities;
	}

	/**
	 * �����ƻ�ȡʵ��
	 * @param name
	 * @return
	 */
	public Identity getIdentity(String name){
		if (null == name){
			return null;
		}
		
		if (null == identities){
			return null;
		}
		
		int size = identities.size();
		
		for (int i = 0; i < size; i++){
			Identity f = identities.get(i);
			if (f.getName().equals(name)){
				return f;
			}
		}
		
		return null;
		
	}
	/**
	 * �����Ż��ʵ��
	 * @param index
	 * @return
	 */
	public Identity getIdentity(int index){
		if (null == identities){
			return null;
		}
		
		return identities.get(index);
	}
	/**
	 * ������ɾ��ʵ��
	 * @param index
	 * @return
	 */
	public Identity removeIdentity(int index){
		if (null == identities){
			return null;
		}
		
		return identities.remove(index);
	}
	/**
	 * ������ɾ��ʵ��
	 * @param name
	 * @return
	 */
	public Identity removeIdentity(String name){
		if (null == name){
			return null;
		}
		
		if (null == identities){
			return null;
		}
		
		int size = identities.size();
		
		for (int i = 0; i < size; i++){
			Identity f = identities.get(i);
			if (f.getName().equals(name)){
				return identities.remove(i);
			}
		}
		
		return null;
	}
	
	

	/**
	 * ��ȡaugment����Ŀ
	 * @return
	 * @see com.netscenery.model.Augment
	 */
	public int getAugmentsNumber(){
		if (null == this.augments){
			return 0;
		}
		return this.augments.size();
	}
	/**
	 * ���ָ������ƴ���augment
	 * @param name
	 * @return
	 * @throws ModelException 
	 * @see com.netscenery.model.Augment
	 */
	public Augment createAugment(String name) throws ModelException{
		if (null == name){
			return null;
		}
		
		return new Augment(newSubEnv(),name);
	}
	/**
	 * ���һ��Augment
	 * @param n
	 * @return
	 * @see com.netscenery.model.Augment
	 */
	public boolean addAugment(Augment n){
		if(null == n){
			return false;
		}
		
		if (null == this.augments){
			this.augments = new ArrayList<Augment>(1);
		}
		if (null != this.getAugment(n.getName())){
			return false;
		}
		return this.augments.add(n);
		

	}
	/**
	 * �����Ż�ȡAugment
	 * @param index
	 * @return
	 * @see com.netscenery.model.Augment
	 */
	public Augment getAugment(int index){
		if (null == this.augments){
			return null;
		}
		if (index >= this.augments.size()){
			return null;
		}
		return this.augments.get(index);
	}
	/**
	 * �����ƻ�ȡaugment
	 * @param name
	 * @return
	 * @see com.netscenery.model.Augment
	 */
	public Augment getAugment(String name){
		if (null == this.augments){
			return null;
		}
		int size = augments.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Augment n = this.augments.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return n;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ��augment
	 * @param index
	 * @return Augment
	 * @see com.netscenery.model.Augment
	 */
	public Augment removeAugment(int index){
		if (null == this.augments){
			return null;
		}
		if (index >= this.augments.size()){
			return null;
		}
		return this.augments.remove(index);
	}
	/**
	 * ������ɾ��augment
	 * @param name
	 * @return Augment
	 * @see com.netscenery.model.Augment
	 */
	public Augment removeAugment(String name){
		if (null == this.augments){
			return null;
		}
		int size = augments.size();
		if (size <= 0){
			return null;
		}
		
		
		for (int i = 0; i < size; i++){
			Augment n = this.augments.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return augments.remove(i);
				}
			}
		}
		return null;
	}
	

	/**
	 * ��ȡgrouping����Ŀ
	 * @return
	 * @see com.netscenery.model.Grouping
	 */
	public int getGroupingsNumber(){
		if (null == this.groupings){
			return 0;
		}
		return this.groupings.size();
	}
	/**
	 * ���ָ������ƴ���grouping
	 * @param name
	 * @return
	 * @throws ModelException 
	 * @see com.netscenery.model.Grouping
	 */
	public Grouping createGrouping(String name) throws ModelException{
		if (null == name){
			return null;
		}
		
		return new Grouping(newSubEnv(),name);
	}
	/**
	 * ���һ��grouping
	 * @param n
	 * @return
	 * @see com.netscenery.model.Grouping
	 */
	public boolean addGrouping(Grouping n){
		if(null == n){
			return false;
		}
		
		if (null == this.groupings){
			this.groupings = new ArrayList<Grouping>(1);
		}
		if (null != this.getGrouping(n.getName())){
			return false;
		}
		return this.groupings.add(n);
		

	}
	/**
	 * �����Ż�ȡGrouping
	 * @param index
	 * @return
	 * @see com.netscenery.model.Grouping
	 */
	public Grouping getGrouping(int index){
		if (null == this.groupings){
			return null;
		}
		if (index >= this.groupings.size()){
			return null;
		}
		return this.groupings.get(index);
	}
	/**
	 * �����ƻ�ȡGrouping
	 * @param name
	 * @return
	 * @see com.netscenery.model.Grouping
	 */
	public Grouping getGrouping(String name){
		if (null == this.groupings){
			return null;
		}
		int size = groupings.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Grouping n = this.groupings.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return n;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ��Grouping
	 * @param index
	 * @return Grouping
	 * @see com.netscenery.model.Grouping
	 */
	public Grouping removeGrouping(int index){
		if (null == this.groupings){
			return null;
		}
		if (index >= this.groupings.size()){
			return null;
		}
		return this.groupings.remove(index);
	}
	/**
	 * ������ɾ��Grouping
	 * @param name
	 * @return Grouping
	 * @see com.netscenery.model.Grouping
	 */
	public Grouping removeGrouping(String name){
		if (null == this.groupings){
			return null;
		}
		int size = groupings.size();
		if (size <= 0){
			return null;
		}
		
		
		for (int i = 0; i < size; i++){
			Grouping n = this.groupings.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return groupings.remove(i);
				}
			}
		}
		return null;
	}

	
	/**
	 * ��ȡdeviation����Ŀ
	 * @return
	 * @see com.netscenery.model.Deviation
	 */
	public int getDeviationsNumber(){
		if (null == this.deviations){
			return 0;
		}
		return this.deviations.size();
	}
	/**
	 * ���ָ������ƴ���deviation
	 * @param name
	 * @return
	 * @throws ModelException 
	 * @see com.netscenery.model.Deviation
	 */
	public Deviation createDeviation(String name) throws ModelException{
		if (null == name){
			return null;
		}
		
		return new Deviation(newSubEnv(),name);
	}
	/**
	 * ���һ��deviation
	 * @param n
	 * @return
	 * @see com.netscenery.model.Deviation
	 */
	public boolean addDeviation(Deviation n){
		if(null == n){
			return false;
		}
		
		if (null == this.deviations){
			this.deviations = new ArrayList<Deviation>(1);
		}
		if (null != this.getDeviation(n.getName())){
			return false;
		}
		return this.deviations.add(n);
		

	}
	/**
	 * �����Ż�ȡdeviation
	 * @param index
	 * @return
	 * @see com.netscenery.model.Deviation
	 */
	public Deviation getDeviation(int index){
		if (null == this.deviations){
			return null;
		}
		if (index >= this.deviations.size()){
			return null;
		}
		return this.deviations.get(index);
	}
	/**
	 * �����ƻ�ȡdeviation
	 * @param name
	 * @return
	 * @see com.netscenery.model.Deviation
	 */
	public Deviation getDeviation(String name){
		if (null == this.deviations){
			return null;
		}
		int size = deviations.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Deviation n = this.deviations.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return n;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ��Deviation
	 * @param index
	 * @return Deviation
	 * @see com.netscenery.model.Deviation
	 */
	public Deviation removeDeviation(int index){
		if (null == this.deviations){
			return null;
		}
		if (index >= this.deviations.size()){
			return null;
		}
		return this.deviations.remove(index);
	}
	/**
	 * ������ɾ��Deviation
	 * @param name
	 * @return Deviation
	 * @see com.netscenery.model.Deviation
	 */
	public Deviation removeDeviation(String name){
		if (null == this.deviations){
			return null;
		}
		int size = deviations.size();
		if (size <= 0){
			return null;
		}
		
		
		for (int i = 0; i < size; i++){
			Deviation n = this.deviations.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return deviations.remove(i);
				}
			}
		}
		return null;
	}
	/**
	 * 
	 * @return
	 * @see com.netscenery.model.Anyxml
	 */
	public int getNotificationsNumber(){
		if (null == this.notifications){
			return 0;
		}
		return this.notifications.size();
	}
	/**
	 * ���ָ������ƴ���anyxml
	 * @param name
	 * @return
	 * @throws ModelException 
	 * @see com.netscenery.model.Anyxml
	 */
	public Notification createNotification(String name) throws ModelException{
		if (null == name){
			return null;
		}
		
		return new Notification(newSubEnv(),name);
	}
	/**
	 * ���һ��Anyxml
	 * @param n
	 * @return
	 * @see com.netscenery.model.Anyxml
	 */
	public boolean addNotification(Notification n){
		if(null == n){
			return false;
		}
		
		if (null == this.notifications){
			this.notifications = new ArrayList<Notification>(1);
		}
		if (null != this.getNotification(n.getName())){
			return false;
		}
		return this.notifications.add(n);
		

	}
	/**
	 * �����Ż�ȡAnyxml
	 * @param index
	 * @return
	 * @see com.netscenery.model.Anyxml
	 */
	public Notification getNotification(int index){
		if (null == this.notifications){
			return null;
		}
		if (index >= this.notifications.size()){
			return null;
		}
		return this.notifications.get(index);
	}
	/**
	 * �����ƻ�ȡanyxml
	 * @param name
	 * @return
	 * @see com.netscenery.model.Anyxml
	 */
	public Notification getNotification(String name){
		if (null == this.notifications){
			return null;
		}
		int size = notifications.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Notification n = this.notifications.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return n;
				}
			}
		}
		return null;
	}
	/**
	 * ������ɾ��anyxml
	 * @param index
	 * @return Anyxml
	 * @see com.netscenery.model.Anyxml
	 */
	public Notification removeNotification(int index){
		if (null == this.notifications){
			return null;
		}
		if (index >= this.notifications.size()){
			return null;
		}
		return this.notifications.remove(index);
	}
	/**
	 * ������ɾ��anyxml
	 * @param name
	 * @return Anyxml
	 * @see com.netscenery.model.Anyxml
	 */
	public Notification removeNotification(String name){
		if (null == this.notifications){
			return null;
		}
		int size = notifications.size();
		if (size <= 0){
			return null;
		}
		
		
		for (int i = 0; i < size; i++){
			Notification n = this.notifications.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return notifications.remove(i);
				}
			}
		}
		return null;
	}

	
	/**
	 * 
	 * @return
	 */
	public int getRpcsNumber(){
		if (null == this.rpcs){
			return 0;
		}
		return this.rpcs.size();
	}
	/**
	 * 
	 * @param name
	 * @return
	 * @throws ModelException
	 */
	public Rpc createRpc(String name) throws ModelException{
		if (null == name){
			return null;
		}
		
		return new Rpc(newSubEnv(),name);
	}
	/**
	 * 
	 * @param n
	 * @return
	 */
	public boolean addRpc(Rpc n){
		if(null == n){
			return false;
		}
		
		if (null == this.rpcs){
			this.rpcs = new ArrayList<Rpc>(1);
		}
		if (null != this.getRpc(n.getName())){
			return false;
		}
		return this.rpcs.add(n);
		

	}
	/**
	 * 
	 * @param index
	 * @return
	 */
	public Rpc getRpc(int index){
		if (null == this.rpcs){
			return null;
		}
		if (index >= this.rpcs.size()){
			return null;
		}
		return this.rpcs.get(index);
	}
	/**
	 * 
	 * @param name
	 * @return
	 */
	public Rpc getRpc(String name){
		if (null == this.rpcs){
			return null;
		}
		int size = rpcs.size();
		if (size <= 0){
			return null;
		}
		
		for (int i = 0; i < size; i++){
			Rpc n = this.rpcs.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return n;
				}
			}
		}
		return null;
	}
	/**
	 * 
	 * @param index
	 * @return
	 */
	public Rpc removeRpc(int index){
		if (null == this.rpcs){
			return null;
		}
		if (index >= this.rpcs.size()){
			return null;
		}
		return this.rpcs.remove(index);
	}
	/**
	 * 
	 * @param name
	 * @return
	 */
	public Rpc removeRpc(String name){
		if (null == this.rpcs){
			return null;
		}
		int size = rpcs.size();
		if (size <= 0){
			return null;
		}
		
		
		for (int i = 0; i < size; i++){
			Rpc n = this.rpcs.get(i);
			if (null != n){
				if (n.getName().equals(name)){
					return rpcs.remove(i);
				}
			}
		}
		return null;
	}
	/**
	 * ���ǰ׺��ȡģ��
	 */
	public Module getModule(String prefix){
		if (null == prefix){
			return null;
		}
		
		if (this instanceof MainModule){
			if (((MainModule)this).getPrefix().equals(prefix)){
				return this;
			}
		}
		
//		if (this instanceof SubModule){
//			if (((SubModule)this).getBelongsto().getPrefix().equals(prefix)){
//				String modulename = ((SubModule)this).getBelongsto().getName();
//				if (null != env){
//					return env.getModule(modulename);
//				}
//			}
//		}
		
		int importNumber = this.getImportsNumber();
		if (0 != importNumber){
			for (int i = 0; i < importNumber; i++){
				Import imp = this.getImport(i);
				if (null == imp){
					continue;
				}
				
				if (imp.getPrefix().equals(prefix)){
					return imp.getImportedModule();
				}
			}
		}
		return null;
		
	}
	/**
	 * ���ģ���ȡprefix
	 * @param module
	 * @return
	 */
	public String getModulePrefix(Module module){
		if (null == module){
			return null;
		}
		
		//�����ģ�鱾�?�򷵻������prefix
		if (this.equals(module)){
			if (this instanceof MainModule){
				return ((MainModule)this).getPrefix();
			}
			else {
				SubModule sb = (SubModule)module;
				MainModule mm = (MainModule) env.getModule(sb.getBelongsto().getName());
				return mm.getPrefix();
			}

		}
		else {
			int importNumber = this.getImportsNumber();
			if (0 != importNumber){
				for (int i = 0; i < importNumber; i++){
					Import imp = this.getImport(i);
					if (null == imp){
						continue;
					}
					
					if (imp.getName().equals(module.getName())){
						return imp.getPrefix();
					}
				}
			}
			
			return null;
		}
		
		
	}
	
	private boolean checkHeader(){
		//TODO
		return true;
	}
	
	private boolean checkMeta(){
		//TODO
		return true;
	}
	
	private boolean checkLinkage(){
		//TODO
		return true;
	}
	
	private boolean checkRevision(){
		//TODO
		return true;
	}

	/**
	 *������֯��YANG���ṹ
	 * @return
	 */
	protected YangStatement buildOrgYangStatement() {

		if(null != this.getOrganization()){
			YangStatement organization = new YangStatement(
					YangStatement.YANG_STATEMENT_ORGANIZATION,
					this.getOrganization());
			return organization;
			
		}
		
		return null;
	}
	/**
	 * ������ϵ��ʽ��YANG���ṹ
	 * @return
	 */
	protected YangStatement buildContactYangStatement() {
		if(null != this.getContact()){
			YangStatement contact = new YangStatement(
					YangStatement.YANG_STATEMENT_CONTACT,
					this.getContact());
			return contact;
		}
		return null;
	}
	
	/**
	 * ����������YANG���ṹ
	 * @return
	 */
	protected YangStatement buildDesrYangStatement() {
		if(null != this.getDescription()){
			YangStatement description = new YangStatement(
					YangStatement.YANG_STATEMENT_DESCRIPTION,
					this.getDescription());
			return description;
		}
		return null;
	}
	
	/**
	 * �����ο���YANG���ṹ
	 * @return
	 * 	 
	 */
	protected YangStatement buildRefYangStatement() {
		if(null != this.getReference()){
			YangStatement reference = new YangStatement(
					YangStatement.YANG_STATEMENT_REFERENCE,
					this.getReference());
			return reference;
		}
		
		return null;
	}
	
	/**
	 * �������YANG���ṹ
	 * @return
	 */
	protected ArrayList<YangStatement> buildIncludesYangStatement() {
		if (0 != this.getIncludesNumber()){
			int i = 0;
			int size = this.getIncludesNumber();
			ArrayList<YangStatement> list = new ArrayList<YangStatement>(1);
			
			for (i = 0; i < size; i++){
				Include include = this.getInclude(i);
				if (null != include){
					YangStatement includeStatement = include.writeYang();
					if (null != includeStatement){
						list.add(includeStatement);
					}
					
				}
			}
			
			return list;
		}
		return null;
	}

	/**
	 *  ���������YANG���ṹ
	 * @return
	 */
	protected ArrayList<YangStatement> buildImportsYangStatement() {
		if (0 != this.getImportsNumber()){
			int i = 0;
			int size = this.getImportsNumber();
			ArrayList<YangStatement> list = new ArrayList<YangStatement>(1);
			for (i = 0; i < size; i++){
				Import importElement = this.getImport(i);
				if (null != importElement){
					YangStatement importStatement = importElement.writeYang();
					if (null != importStatement){
						list.add(importStatement);
					}
					
				}
			}
			return list;
		}
		return null;
	}
	
	/**
	 *  ����Revision��YANG���ṹ
	 * @return
	 */
	protected ArrayList<YangStatement> buildRevisonsYangStatement() {
		if (0 != this.getRevisionsNumber()){
			int i = 0;
			int size = this.getRevisionsNumber();
			ArrayList<YangStatement> list = new ArrayList<YangStatement>(1);
			for (i = 0; i < size; i++){
				Revision revison = this.getRevision(i);
				if (null != revison){
					YangStatement revisionStatement = revison.writeYang();
					if (null != revisionStatement){
						list.add(revisionStatement);
					}
					
				}
			}
			return list;
		}
		return null;
	}
	
	/**
	 * @param statement
	 */
	protected void buildModuleYangStatement(YangStatement statement) {
		//linkage statements
		/*
		 * �������YANG���ṹ����������뵽module��ȥ
		 */
		ArrayList<YangStatement> list = buildIncludesYangStatement();
		if (null != list){
			if (0 != list.size()){
				for (int i= 0;i<list.size();i++){
					YangStatement include = list.get(i);
					if (null != include){
						statement.addChild(include);
					}
				}
			}
		}
		/*
		 * ���������YANG���ṹ����������뵽module��ȥ
		 */
		ArrayList<YangStatement> imortlist = buildImportsYangStatement();
		if (null != imortlist){
			if (0 != imortlist.size()){
				for (int i= 0;i<imortlist.size();i++){
					YangStatement importElement = imortlist.get(i);
					if (null != importElement){
						statement.addChild(importElement);
					}
				}
			}
		}
		//meta-stmts
		/*
		 * ������֯��YANG���ṹ����������뵽module��ȥ
		 */
		YangStatement orgnaization = buildOrgYangStatement();
		if (null != orgnaization){
			statement.addChild(orgnaization);	
		}
			
		/*
		 * ������ϵ��ʽ��YANG���ṹ����������뵽module��ȥ
		 */
			
		YangStatement contact = buildContactYangStatement();
		if (null != contact){
			statement.addChild(contact);	
		}
			
		/*
		 * ����������YANG���ṹ����������뵽module��ȥ
		 */
		YangStatement description = buildDesrYangStatement();
		if (null != description){
			statement.addChild(description);	
		}
		/*
		 * �����ο���YANG���ṹ����������뵽module��ȥ
		 */

		YangStatement reference = buildRefYangStatement();
		if (null != reference){
			statement.addChild(reference);	
		}


		//revision-stmts
		/*
		 * Revision
		 */
		ArrayList<YangStatement> Revisionlist = buildRevisonsYangStatement();
		if (null != Revisionlist){
			if (0 != Revisionlist.size()){
				for (int i= 0;i<Revisionlist.size();i++){
					YangStatement revisonElement = Revisionlist.get(i);
					if (null != revisonElement){
						statement.addChild(revisonElement);
					}
				}
			}
		}
		// body-stmts
		//extension
		if (null != this.extensions){
			int size = this.getExtensionsNumber();
			for (int i = 0; i < size; i++){
				Extension ex = this.getExtension(i);
				if (null != ex){
					YangStatement exstat = ex.writeYang();
					if (null == exstat){
						continue;
					}
					statement.addChild(exstat);
				}
			}
		}
		//feature
		if (null != this.features){
			int size = this.getFeaturesNumber();
			for (int i = 0; i < size; i++){
				Feature ex = this.getFeature(i);
				if (null != ex){
					YangStatement exstat = ex.writeYang();
					if (null == exstat){
						continue;
					}
					statement.addChild(exstat);
				}
			}
		}
		//identity
		if (null != this.identities){
			int size = this.getIdentitiesNumber();
			for (int i = 0; i < size; i++){
				Identity ex = this.getIdentity(i);
				if (null != ex){
					YangStatement exstat = ex.writeYang();
					if (null == exstat){
						continue;
					}
					statement.addChild(exstat);
				}
			}
		}
		/*
		 * typedefs
		 */
		if (null != this.typedefs){
			int size = this.getTypedefsNumber();
			for (int i = 0; i < size; i++){
				Typedef def = this.getTypedef(i);
				if (null != def){
					YangStatement defstat = def.writeYang();
					if (null == defstat){
						continue;
					}
					statement.addChild(defstat);
				}
			}
		}
		/*
		 * groupings
		 */
		if (null != this.groupings){
			int size = this.getGroupingsNumber();
			for (int i = 0; i < size; i++){
				Grouping grp = this.getGrouping(i);
				if (null != grp){
					YangStatement grpstat = grp.writeYang();
					if (null == grpstat){
						continue;
					}
					statement.addChild(grpstat);
				}
			}
		}

		/*
		 * datadefs
		 */
		if (null != this.dataDefs
				&& 0 != dataDefs.getDataDefsNumber()){
			int size = dataDefs.getDataDefsNumber();
			for (int i = 0; i < size; i++){
				DataDefElement n = dataDefs.getDataDef(i);
				if (null != n){
					YangStatement nodestat = n.writeYang();
					if (null == nodestat){
						continue;
					}
					statement.addChild(nodestat);
				}
			}
		}
		
		
		
		/*
		 * augments
		 */
		if (null != this.augments){
			int size = this.getAugmentsNumber();
			for (int i = 0; i < size; i++){
				Augment n = this.getAugment(i);
				if (null != n){
					YangStatement augstat = n.writeYang();
					if (null == augstat){
						continue;
					}
					statement.addChild(augstat);
				}
			}
		}
		//rpcs
		
		if (null != this.rpcs){
			int size = this.getRpcsNumber();
			for (int i = 0; i < size; i++){
				Rpc n = this.getRpc(i);
				if (null != n){
					YangStatement rpcstat = n.writeYang();
					if (null == rpcstat){
						continue;
					}
					statement.addChild(rpcstat);
				}
			}
		}
		/*
		 * notifications
		 */
		if (null != this.notifications){
			int size = this.getNotificationsNumber();
			for (int i = 0; i < size; i++){
				Notification n = this.getNotification(i);
				if (null != n){
					YangStatement notificationstat = n.writeYang();
					if (null == notificationstat){
						continue;
					}
					statement.addChild(notificationstat);
				}
			}
		}
		/*
		 * deviations
		 */
		if (null != this.deviations){
			int size = this.getDeviationsNumber();
			for (int i = 0; i < size; i++){
				Deviation n = this.getDeviation(i);
				if (null != n){
					YangStatement devstat = n.writeYang();
					if (null == devstat){
						continue;
					}
					statement.addChild(devstat);
				}
			}
		}		
		

	}

	protected void buildModuleXMLElement(Element module) {
		
		if (null == module){
			return;
		}
		//linkage-stmts
		/*
		 *�� 
		 */
		if (0 != this.getIncludesNumber()){
			int i = 0;
			int size = this.getIncludesNumber();
			for (i = 0; i < size; i++){
				Include include = this.getInclude(i);
				if (null != include){
					Element includeXMLNode = include.writeXML();
					if (null != includeXMLNode){
						module.addContent(includeXMLNode);
					}
					
				}
			}
		}
		/*
		 *���� 
		 */
		if (0 != this.getImportsNumber()){
			int i = 0;
			int size = this.getImportsNumber();
			for (i = 0; i < size; i++){
				Import importElement = this.getImport(i);
				if (null != importElement){
					Element importXMLNode = importElement.writeXML();
					if (null != importXMLNode){
						module.addContent(importXMLNode);
					}
					
				}
			}
		}	
		//meta-stmts
		/*
		 * ��֯
		 */
		if (null != this.organization){
			Element organization = new Element(XMLTag.XML_TAG_ORGANIZATION);
			organization.setText(this.organization);
			module.addContent(organization);
		}
		/*
		 * ��ϵ��ʽ
		 */
		if (null != this.contact){
			Element contact = new Element(XMLTag.XML_TAG_CONTACT);
			contact.setText(this.contact);
			module.addContent(contact);
		}		
		
		/*
		 * ����
		 */
		if (null != this.description){
			Element descr = new Element(XMLTag.XML_TAG_DESCRIPTION);
			descr.setText(this.description);
			module.addContent(descr);
		}	
		
		/*
		 * �ο�
		 */
		if (null != this.reference){
			Element ref = new Element(XMLTag.XML_TAG_REFERENCE);
			ref.setText(this.reference);
			module.addContent(ref);
		}	
		
		//revision-stmts
		
		/*
		 *Revision
		 */
		if (0 != this.getRevisionsNumber()){
			int i = 0;
			int size = this.getRevisionsNumber();
			for (i = 0; i < size; i++){
				Revision revision = this.getRevision(i);
				if (null != revision){
					Element revisionXMLNode = revision.writeXML();
					if (null != revisionXMLNode){
						module.addContent(revisionXMLNode);
					}
					
				}
			}
		}	
		// body-stmts
		//extension
		if (null != this.extensions){
			int size = this.getExtensionsNumber();
			for (int i = 0; i < size; i++){
				Extension ex = this.getExtension(i);
				if (null != ex){
					Element exstat = ex.writeXML();
					if (null == exstat){
						continue;
					}
					module.addContent(exstat);
				}
			}
		}
		//feature
		if (null != this.features){
			int size = this.getFeaturesNumber();
			for (int i = 0; i < size; i++){
				Feature ex = this.getFeature(i);
				if (null != ex){
					Element exstat = ex.writeXML();
					if (null == exstat){
						continue;
					}
					module.addContent(exstat);
				}
			}
		}
		/*
		 * typedefs
		 */
		if (null != this.typedefs){
			int size = this.getTypedefsNumber();
			for (int i = 0; i < size; i++){
				Typedef def = this.getTypedef(i);
				if (null != def){
					Element defstat = def.writeXML();
					if (null == defstat){
						continue;
					}
					module.addContent(defstat);
				}
			}
		}
		
		//datadefs
		if (null != this.dataDefs
				&& 0 != this.dataDefs.getDataDefsNumber()){
			int size = this.dataDefs.getDataDefsNumber();
			for (int i = 0; i < size; i++){
				DataDefElement n = dataDefs.getDataDef(i);
				if (null != n){
					Element node = n.writeXML();
					if (null == node){
						continue;
					}
					module.addContent(node);
				}
			}
		}		
	}
	
protected void buildModuleYinElement(Element module) {
		
		if (null == module){
			return;
		}
		//linkage-stmts
		/*
		 *�� 
		 */
		if (0 != this.getIncludesNumber()){
			int i = 0;
			int size = this.getIncludesNumber();
			for (i = 0; i < size; i++){
				Include include = this.getInclude(i);
				if (null != include){
					Element includeYinNode = include.writeYin();
					if (null != includeYinNode){
						module.addContent(includeYinNode);
					}
					
				}
			}
		}
		/*
		 *���� 
		 */
		if (0 != this.getImportsNumber()){
			int i = 0;
			int size = this.getImportsNumber();
			for (i = 0; i < size; i++){
				Import importElement = this.getImport(i);
				if (null != importElement){
					Element importYinNode = importElement.writeYin();
					if (null != importYinNode){
						module.addContent(importYinNode);
					}
					
				}
			}
		}	
		//meta-stmts
		/*
		 * ��֯
		 */
		if (null != this.organization){
			Element organization = new Element(YangStatement.YANG_STATEMENT_ORGANIZATION,env.getNs());
			Element text = new Element(XMLTag.XML_TAG_TEXT,env.getNs());
			text.setText(this.organization);
			organization.addContent(text);
			module.addContent(organization);
		}
		/*
		 * ��ϵ��ʽ
		 */
		if (null != this.contact){
			Element contact = new Element(YangStatement.YANG_STATEMENT_CONTACT,env.getNs());
			Element text = new Element(XMLTag.XML_TAG_TEXT,env.getNs());
			text.setText(this.contact);
			contact.addContent(text);
			module.addContent(contact);
		}		
		
		/*
		 * ����
		 */
		if (null != this.description){
			Element descr = new Element(YangStatement.YANG_STATEMENT_DESCRIPTION,env.getNs());
			Element text = new Element(XMLTag.XML_TAG_TEXT,env.getNs());
			text.setText(this.description);
			descr.addContent(text);
			module.addContent(descr);
		}	
		
		/*
		 * �ο�
		 */
		if (null != this.reference){
			Element ref = new Element(YangStatement.YANG_STATEMENT_REFERENCE,env.getNs());
			Element text = new Element(XMLTag.XML_TAG_TEXT,env.getNs());
			text.setText(this.reference);
			ref.addContent(text);
			module.addContent(ref);
		}	
		
		//revision-stmts
		
		/*
		 *Revision
		 */
		if (0 != this.getRevisionsNumber()){
			int i = 0;
			int size = this.getRevisionsNumber();
			for (i = 0; i < size; i++){
				Revision revision = this.getRevision(i);
				if (null != revision){
					Element revisionXMLNode = revision.writeYin();
					if (null != revisionXMLNode){
						module.addContent(revisionXMLNode);
					}
					
				}
			}
		}	
		// body-stmts
		//extension
		if (null != this.extensions){
			int size = this.getExtensionsNumber();
			for (int i = 0; i < size; i++){
				Extension ex = this.getExtension(i);
				if (null != ex){
					Element exstat = ex.writeYin();
					if (null == exstat){
						continue;
					}
					module.addContent(exstat);
				}
			}
		}
		//feature
		if (null != this.features){
			int size = this.getFeaturesNumber();
			for (int i = 0; i < size; i++){
				Feature ex = this.getFeature(i);
				if (null != ex){
					Element exstat = ex.writeYin();
					if (null == exstat){
						continue;
					}
					module.addContent(exstat);
				}
			}
		}
		//identity
		if (null != this.identities){
			int size = this.getIdentitiesNumber();
			for (int i = 0; i < size; i++){
				Identity ex = this.getIdentity(i);
				if (null != ex){
					Element exstat = ex.writeYin();
					if (null == exstat){
						continue;
					}
					module.addContent(exstat);
				}
			}
		}
		/*
		 * typedefs
		 */
		if (null != this.typedefs){
			int size = this.getTypedefsNumber();
			for (int i = 0; i < size; i++){
				Typedef def = this.getTypedef(i);
				if (null != def){
					Element defstat = def.writeYin();
					if (null == defstat){
						continue;
					}
					module.addContent(defstat);
				}
			}
		}
		/*
		 * groupings
		 */
		if (null != this.groupings){
			int size = this.getGroupingsNumber();
			for (int i = 0; i < size; i++){
				Grouping grp = this.getGrouping(i);
				if (null != grp){
					Element grpstat = grp.writeYin();
					if (null == grpstat){
						continue;
					}
					module.addContent(grpstat);
				}
			}
		}

		//datadefs
		if (null != this.dataDefs
				&& 0 != dataDefs.getDataDefsNumber()){
			int size = dataDefs.getDataDefsNumber();
			for (int i = 0; i < size; i++){
				DataDefElement n = dataDefs.getDataDef(i);
				if (null != n){
					Element node = n.writeYin();
					if (null == node){
						continue;
					}
					module.addContent(node);
				}
			}
		}	
		
	
		
		//augments
		if (null != this.augments){
			int size = this.getAugmentsNumber();
			for (int i = 0; i < size; i++){
				Augment n = this.getAugment(i);
				if (null != n){
					Element aug = n.writeYin();
					if (null == aug){
						continue;
					}
					module.addContent(aug);
				}
			}
		}	
		//rpcs
		if (null != this.rpcs){
			int size = this.getRpcsNumber();
			for (int i = 0; i < size; i++){
				Rpc n = this.getRpc(i);
				if (null != n){
					Element rpcstat = n.writeYin();
					if (null == rpcstat){
						continue;
					}
					module.addContent(rpcstat);
				}
			}
		}	
		//notifications
		if (null != this.notifications){
			int size = this.getNotificationsNumber();
			for (int i = 0; i < size; i++){
				Notification n = this.getNotification(i);
				if (null != n){
					Element notificationelement = n.writeYin();
					if (null == notificationelement){
						continue;
					}
					module.addContent(notificationelement);
				}
			}
		}	
		//deviations
		if (null != this.deviations){
			int size = this.getDeviationsNumber();
			for (int i = 0; i < size; i++){
				Deviation n = this.getDeviation(i);
				if (null != n){
					Element dev = n.writeYin();
					if (null == dev){
						continue;
					}
					module.addContent(dev);
				}
			}
		}
	}

	@Override
	/**
	 * ��ģ�鵼��ΪYANG���
	 */
	public YangStatement toYang() {
		YangStatement statement = null;
		//header
		if (this instanceof MainModule){
			assert(null != ((MainModule)this).name);

			/*
			 * ����Module��YANG���ṹ
			 */
			statement = new YangStatement(YangStatement.YANG_STATEMENT_MODULE,this.name);
			/*
			 * ��������ռ��YANG���ṹ����������뵽module��ȥ
			 */
			if (null != ((MainModule)this).getNamespace()){
				YangStatement namespace = new YangStatement(YangStatement.YANG_STATEMENT_NAMESPACE,
						((MainModule)this).getNamespace());
				statement.addChild(namespace);
			}
			
			/*
			 * ����ǰ׺��YANG���ṹ����������뵽module��ȥ
			 */
			if (null != ((MainModule)this).getPrefix()){
				YangStatement prefix = new YangStatement(YangStatement.YANG_STATEMENT_PREFIX,
						((MainModule)this).getPrefix());
				statement.addChild(prefix);		
			}
			
		}
		else if (this instanceof SubModule){
			//TODO:
			statement = new YangStatement(YangStatement.YANG_STATEMENT_SUBMODULE,this.name);
			//����belongsto��YANG���ṹ
			if (null != ((SubModule)this).getBelongsto()){
				YangStatement belongsTo = ((SubModule)this).getBelongsto().writeYang();
				statement.addChild(belongsTo);
			}
			
		}
		else {
			throw new java.lang.ClassCastException("error class");
		}
		
		buildModuleYangStatement(statement);
		
		
		return statement;
	}

	@Override
	/**
	 * ��ģ�鵼��ΪXML���
	 */
	public Element toXML() {
		
		Element module = null;
		
		if (this instanceof MainModule){

			module = new Element(XMLTag.XML_TAG_MODULE);
			/*ģ����*/
			Element name = new Element("name");
			name.setText(this.name);
			module.addContent(name);
			/*
			 * ǰ׺
			 */
			if (null != ((MainModule)this).getPrefix()){
				Element prefix = new Element(XMLTag.XML_TAG_PREFIX);
				prefix.setText(((MainModule)this).getPrefix());
				module.addContent(prefix);	
			}
			
			/*
			 * ����ռ�
			 */
			if (null != ((MainModule)this).getNamespace()){
				Element namespace = new Element(XMLTag.XML_TAG_NAMESPACE);
				namespace.setText(((MainModule)this).getNamespace());
				module.addContent(namespace);
			}
			
			

		}
		else if (this instanceof SubModule){
			module = new Element(XMLTag.XML_TAG_SUBMODULE);
			/*��ģ����*/
			Element name = new Element(XMLTag.XML_TAG_NAME);
			name.setText(this.name);
			module.addContent(name);
			//belongs-to
			if (null != ((SubModule)this).getBelongsto()){
				Element belongsto = ((SubModule)this).getBelongsto().writeXML();
				module.addContent(belongsto);
			}
			
		}
		else {
			throw new java.lang.ClassCastException("error class");
		}
		
		
		/*
		 * ͨ��ģ�鲿��
		 * */
		buildModuleXMLElement(module);
		return module;

	}
	@Override
	/**
	 * ��ģ�鵼��ΪXML���
	 */
	public Element toYin() {
		
		Element module = null;
		
		if (this instanceof MainModule){

			module = new Element(YangStatement.YANG_STATEMENT_MODULE);
			//YIN����ռ�
			Namespace nm = Namespace.getNamespace("urn:ietf:params:xml:ns:yang:yin:1");
			module.setNamespace(nm);
			if (null == env.getNs()){
				env.setNs(nm);
			}
			//����������ռ�
			Namespace namespaceModule = Namespace.getNamespace(((MainModule)this).getPrefix(),
					((MainModule)this).getNamespace());
			module.addNamespaceDeclaration(namespaceModule);
			if(0 != getImportsNumber()){
				int size = getImportsNumber();
				for(int i = 0; i < size; i++){
					Import imp = getImport(i);
					if (null != imp){
						MainModule mm = imp.getImportedModule();
						Namespace namespaceimp = Namespace.getNamespace(imp.getPrefix(),
								mm.getNamespace());
						module.addNamespaceDeclaration(namespaceimp);
					}
				}
			}
			/*ģ����*/
			Attribute name = new Attribute(XMLTag.XML_TAG_NAME,this.name);
			module.setAttribute(name);
			
			/*
			 * ǰ׺
			 */
			if (null != ((MainModule)this).getPrefix()){
				Element prefix = new Element(YangStatement.YANG_STATEMENT_PREFIX,nm);
				Attribute value = new Attribute(XMLTag.XML_TAG_VALUE,
						((MainModule)this).getPrefix());
				prefix.setAttribute(value);
				module.addContent(prefix);	
			}
			
			/*
			 * ����ռ�
			 */
			if (null != ((MainModule)this).getNamespace()){
				Element namespace = new Element(YangStatement.YANG_STATEMENT_NAMESPACE,nm);
				Attribute uri = new Attribute(XMLTag.XML_TAG_URI,
						((MainModule)this).getNamespace());
				namespace.setAttribute(uri);
				module.addContent(namespace);
			}
			
			

		}
		else if (this instanceof SubModule){
			module = new Element(YangStatement.YANG_STATEMENT_SUBMODULE);
			//YIN����ռ�
			Namespace nm = Namespace.getNamespace("urn:ietf:params:xml:ns:yang:yin:1");
			module.setNamespace(nm);
			//����������ռ�
			if (null != ((SubModule)this).getBelongsto()){
				BelongsTo belongsto = ((SubModule)this).getBelongsto();
				MainModule mm = (MainModule) env.getModule(belongsto.getName());
				Namespace namespaceModule = Namespace.getNamespace(belongsto.getPrefix(),
						mm.getNamespace());
				module.addNamespaceDeclaration(namespaceModule);
			}
			
			if(0 != getImportsNumber()){
				int size = getImportsNumber();
				for(int i = 0; i < size; i++){
					Import imp = getImport(i);
					if (null != imp){
						MainModule mm = imp.getImportedModule();
						Namespace namespaceimp = Namespace.getNamespace(imp.getPrefix(),
								mm.getNamespace());
						module.addNamespaceDeclaration(namespaceimp);
					}
				}
			}
			/*��ģ����*/
			Attribute name = new Attribute(XMLTag.XML_TAG_NAME,this.name);
			module.setAttribute(name);
			//belongs-to
			if (null != ((SubModule)this).getBelongsto()){
				Element belongsto = ((SubModule)this).getBelongsto().writeYin();
				module.addContent(belongsto);
			}
			
		}
		else {
			throw new java.lang.ClassCastException("error class");
		}
		
		
		/*
		 * ͨ��ģ�鲿��
		 * */
		buildModuleYinElement(module);
		return module;

	}
	@Override
	public boolean isFieldMandatory(String field) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	/**
	 * ��ȡXML��䲢ת��Ϊģ��
	 */
	public int readXML(Element element) throws ModelException {
		
		if (null == element){
			return MODELELEMENT_OK;
		}
		
		if (element.getName().equals(XMLTag.XML_TAG_NAME)){
			return MODELELEMENT_OK;
		}
		
		//header 
		if (element.getName().equals(XMLTag.XML_TAG_NAMESPACE)){
			if (this instanceof MainModule){
				MainModule mm =(MainModule)this;
				mm.setNamespace(element.getText());

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		else if (element.getName().equals(XMLTag.XML_TAG_PREFIX)){
			if (this instanceof MainModule){
				MainModule mm =(MainModule)this;
				mm.setPrefix(element.getText());

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		else if (element.getName().equals(XMLTag.XML_TAG_BELONGSTO)){
			if (this instanceof SubModule){
				SubModule sm =(SubModule)this;
				Env subEnv = newSubEnv();
				BelongsTo belongsto = (BelongsTo) ModelElement.parseXML(subEnv, element);
				sm.setBelongsto(belongsto);

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		//linkage
		else if (element.getName().equals(XMLTag.XML_TAG_INCLUDE)){
			if (!checkHeader()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Include include = (Include) ModelElement.parseXML(subEnv, element);
			this.addInclude(include);
		}
		else if (element.getName().equals(XMLTag.XML_TAG_IMPORT)){
			if (!checkHeader()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Import imp = (Import) ModelElement.parseXML(subEnv, element);
			this.addImport(imp);
		}
		//meta
		else if (element.getName().equals(XMLTag.XML_TAG_CONTACT)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setContact(element.getText());
		}
		else if (element.getName().equals(XMLTag.XML_TAG_ORGANIZATION)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setOrganization(element.getText());
		}		
		else if (element.getName().equals(XMLTag.XML_TAG_REFERENCE)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setReference(element.getText());
		}	
		else if (element.getName().equals(XMLTag.XML_TAG_DESCRIPTION)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setDescription(element.getText());
		}	
		//revision
		else if (element.getName().equals(XMLTag.XML_TAG_REVISION)){
			if (!checkMeta()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Revision rev = (Revision) ModelElement.parseXML(subEnv, element);
			this.addRevision(rev);
		}
		//extension
		else if (element.getName().equals(XMLTag.XML_TAG_EXTENSION)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Extension ext = (Extension) ModelElement.parseXML(subEnv, element);
			this.addExtension(ext);
		}
		//feature
		else if (element.getName().equals(XMLTag.XML_TAG_FEATURE)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Feature ext = (Feature) ModelElement.parseXML(subEnv, element);
			this.addFeature(ext);
		}
		/*
		 * typedefs
		 */
		else if (element.getName().equals(XMLTag.XML_TAG_TYPEDEF)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Typedef ext = (Typedef) ModelElement.parseXML(subEnv, element);
			this.addTypedef(ext);
		}
	
		//nodes
		else if (element.getName().equals(XMLTag.XML_TAG_NODE)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Node n = (Node) ModelElement.parseXML(subEnv, element);
			this.dataDefs.addDataDef(n);
		}   
//		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_ANYXML)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_AUGMENT)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_DEVIATION)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_FEATURE)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_GROUPING)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_IDENTITY)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_NOTIFICATION)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_RPC)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_USES)
//				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_YANGVERSION)
//				){
//			return MODELELEMENT_UNSUPPORT;
//		}
		else {
			return MODELELEMENT_FAIL;
		}
		return MODELELEMENT_OK;
	}
	@Override
	/**
	 * ��ȡYIN��䲢ת��Ϊģ��
	 */
	public int readYin(Element element) throws ModelException {
		
		if (null == element){
			return MODELELEMENT_OK;
		}
			
		//header 
		if (element.getName().equals(YangStatement.YANG_STATEMENT_NAMESPACE)){
			if (this instanceof MainModule){
				MainModule mm =(MainModule)this;
				Attribute uri = element.getAttribute(XMLTag.XML_TAG_URI);
				if (null == uri){
					return MODELELEMENT_FAIL;
				}
				
				mm.setNamespace(uri.getValue());

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_PREFIX)){
			if (this instanceof MainModule){
				MainModule mm =(MainModule)this;
				Attribute value = element.getAttribute(XMLTag.XML_TAG_VALUE);
				if (null == value){
					return MODELELEMENT_FAIL;
				}
				mm.setPrefix(value.getValue());

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_BELONGSTO)){
			if (this instanceof SubModule){
				SubModule sm =(SubModule)this;
				Env subEnv = newSubEnv();
				BelongsTo belongsto = (BelongsTo) ModelElement.parseYin(subEnv, element);
				sm.setBelongsto(belongsto);

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		//linkage
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_INCLUDE)){
			if (!checkHeader()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Include include = (Include) ModelElement.parseYin(subEnv, element);
			this.addInclude(include);
		}
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_IMPORT)){
			if (!checkHeader()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Import imp = (Import) ModelElement.parseYin(subEnv, element);
			this.addImport(imp);
		}
		//meta
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_CONTACT)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			Element text = element.getChild(XMLTag.XML_TAG_TEXT,env.getNs());
			if (null == text){
				return MODELELEMENT_FAIL;
			}
			this.setContact(text.getText());
		}
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_ORGANIZATION)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			Element text = element.getChild(XMLTag.XML_TAG_TEXT,env.getNs());
			if (null == text){
				return MODELELEMENT_FAIL;
			}
			this.setOrganization(text.getText());
		}		
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_REFERENCE)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			Element text = element.getChild(XMLTag.XML_TAG_TEXT,env.getNs());
			if (null == text){
				return MODELELEMENT_FAIL;
			}
			this.setReference(text.getText());
		}	
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_DESCRIPTION)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			Element text = element.getChild(XMLTag.XML_TAG_TEXT,env.getNs());
			if (null == text){
				return MODELELEMENT_FAIL;
			}
			this.setDescription(text.getText());
		}	
		//revision
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_REVISION)){
			if (!checkMeta()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Revision rev = (Revision) ModelElement.parseYin(subEnv, element);
			this.addRevision(rev);
		}
		//extension
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_EXTENSION)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Extension ext = (Extension) ModelElement.parseYin(subEnv, element);
			this.addExtension(ext);
		}
		//feature
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_FEATURE)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Feature ext = (Feature) ModelElement.parseYin(subEnv, element);
			this.addFeature(ext);
		}
		//identity
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_IDENTITY)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Identity ext = (Identity) ModelElement.parseYin(subEnv, element);
			this.addIdentity(ext);
		}
		/*
		 * typedefs
		 */
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_TYPEDEF)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Typedef ext = (Typedef) ModelElement.parseYin(subEnv, element);
			this.addTypedef(ext);
		}
		/*
		 * groupings
		 */
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_GROUPING)){

			Env subEnv = newSubEnv();
			Grouping ext = (Grouping) ModelElement.parseYin(subEnv, element);
			this.addGrouping(ext);
		}

		//dataDefs
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_CONTAINER)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_CASE)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_CHOICE)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_LEAF)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_LEAFLIST)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_LIST)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_ANYXML)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_USES)
				){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			DataDefElement n = (DataDefElement) ModelElement.parseYin(subEnv, element);
			this.dataDefs.addDataDef(n);
		} 
		//notification
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_NOTIFICATION)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Notification ext = (Notification) ModelElement.parseYin(subEnv, element);
			this.addNotification(ext);
		}
		//rpc
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_RPC)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Rpc ext = (Rpc) ModelElement.parseYin(subEnv, element);
			this.addRpc(ext);
		}
		//augment
		else if (element.getName().equals(YangKeyword.AUGMENT.getKeyword())){
			Env subEnv = newSubEnv();
			Augment aug = (Augment)ModelElement.parseYin(subEnv, element);
			this.addAugment(aug);
		}
		//deviation
		else if (element.getName().equals(YangKeyword.DEVIATION.getKeyword())){
			Env subEnv = newSubEnv();
			Deviation dev = (Deviation)ModelElement.parseYin(subEnv, element);
			this.addDeviation(dev);
		}
		else if (element.getName().equals(YangStatement.YANG_STATEMENT_RPC)
				|| element.getName().equals(YangStatement.YANG_STATEMENT_YANGVERSION)
				){
			return MODELELEMENT_UNSUPPORT;
		}
		else {
			return MODELELEMENT_FAIL;
		}
		return MODELELEMENT_OK;
	}
	@Override
	/**
	 * ��ȡYANG��䣬��ת��Ϊģ��
	 */
	public int readYANG(YangStatement statement) throws YangParserException, ModelException {
		
		if (null == statement){
			return MODELELEMENT_OK;
		}
		
		//header 
		if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_NAMESPACE)){
			if (this instanceof MainModule){
				MainModule mm =(MainModule)this;
				mm.setNamespace(statement.getArgument());

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_PREFIX)){
			if (this instanceof MainModule){
				MainModule mm =(MainModule)this;
				mm.setPrefix(statement.getArgument());

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_BELONGSTO)){
			if (this instanceof SubModule){
				SubModule sm =(SubModule)this;
				Env subEnv = newSubEnv();
				BelongsTo belongsto = (BelongsTo) ModelElement.parseYANG(subEnv, statement);
				sm.setBelongsto(belongsto);

			}
			else {
				return MODELELEMENT_FAIL;
			}
		}
		//linkage
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_INCLUDE)){
			if (!checkHeader()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Include include = (Include) ModelElement.parseYANG(subEnv, statement);
			this.addInclude(include);
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_IMPORT)){
			if (!checkHeader()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Import imp = (Import) ModelElement.parseYANG(subEnv, statement);
			this.addImport(imp);
		}
		//meta
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_CONTACT)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setContact(statement.getArgument());
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_ORGANIZATION)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setOrganization(statement.getArgument());
		}		
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_REFERENCE)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setReference(statement.getArgument());
		}	
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_DESCRIPTION)){
			if (!checkLinkage()){
				return MODELELEMENT_FAIL;
			}
			this.setDescription(statement.getArgument());
		}	
		//revision
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_REVISION)){
			if (!checkMeta()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Revision rev = (Revision) ModelElement.parseYANG(subEnv, statement);
			this.addRevision(rev);
		}
		//extension
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_EXTENSION)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Extension ext = (Extension) ModelElement.parseYANG(subEnv, statement);
			this.addExtension(ext);
		}
		//feature
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_FEATURE)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Feature ext = (Feature) ModelElement.parseYANG(subEnv, statement);
			this.addFeature(ext);
		}
		//identity
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_IDENTITY)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Identity ext = (Identity) ModelElement.parseYANG(subEnv, statement);
			this.addIdentity(ext);
		}
		/*
		 * typedefs
		 */
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_TYPEDEF)){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			Typedef ext = (Typedef) ModelElement.parseYANG(subEnv, statement);
			this.addTypedef(ext);
		}
		/*
		 * groupings
		 */
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_GROUPING)){

			Env subEnv = newSubEnv();
			Grouping ext = (Grouping) ModelElement.parseYANG(subEnv, statement);
			this.addGrouping(ext);
		}

		//datadefs
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_CONTAINER)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_CASE)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_CHOICE)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_LEAF)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_LEAFLIST)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_LIST)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_ANYXML)
				|| statement.getKeyword().equals(YangStatement.YANG_STATEMENT_USES)
				){
			if (!checkRevision()){
				return MODELELEMENT_FAIL;
			}
			Env subEnv = newSubEnv();
			DataDefElement n = (DataDefElement) ModelElement.parseYANG(subEnv, statement);
			this.dataDefs.addDataDef(n);
		}   
		//notification
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_NOTIFICATION)){
			Env subEnv = newSubEnv();
			Notification f = (Notification) ModelElement.parseYANG(subEnv, statement);
			this.addNotification(f);
		}
		//rpc
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_RPC)){
			Env subEnv = newSubEnv();
			Rpc f = (Rpc) ModelElement.parseYANG(subEnv, statement);
			this.addRpc(f);
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_AUGMENT)){
			Env subEnv = newSubEnv();
			Augment aug = (Augment)ModelElement.parseYANG(subEnv, statement);
			this.addAugment(aug);
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_DEVIATION)){
			Env subEnv = newSubEnv();
			Deviation dev = (Deviation)ModelElement.parseYANG(subEnv, statement);
			this.addDeviation(dev);
		}
		else if (statement.getKeyword().equals(YangStatement.YANG_STATEMENT_YANGVERSION)
				){
			return MODELELEMENT_UNSUPPORT;
		}
		else {
			return MODELELEMENT_FAIL;
		}
				
		return MODELELEMENT_OK;
	}
/**
 * ��ȡģ���ӳ����Ϣ�������Щ�ֶΣ�ÿ���ֶεĴ���������get������set�����ȡ�	
 */
public  MapInfo getMapInfo() throws SecurityException, NoSuchMethodException {
		
		MapInfo mapInfo = new MapInfo();
		mapInfo.setClazz(this.getClass());
/*		MethodInfo create = new MethodInfo();
		create.setMethod(MainModule.class.getMethod("create", Env.class,String.class));

		Parameter[] paras = {new Parameter("env",false),new Parameter("name",true)}; 
		create.setMethodParas(paras);
		mapInfo.setCreate(create);*/
		
		//basic fields
		
		//header
		//name
		LeafFieldMap name = new LeafFieldMap();
		name.setFieldName("name");
		MethodInfo setName = new MethodInfo();
		setName.setMethod(ModelElement.class.getMethod("setName", String.class));
		Parameter[] setNameParas = {new Parameter("name",true)};
		setName.setMethodParas(setNameParas);
		name.setSet(setName);
		
		MethodInfo getName = new MethodInfo();
		getName.setMethod(ModelElement.class.getMethod("getName", null));
		name.setGet(getName);
		mapInfo.addBasicField(name);
		if (this instanceof MainModule){
			//prefix
			LeafFieldMap prefix = new LeafFieldMap();
			prefix.setFieldName("prefix");
			MethodInfo setPrefix = new MethodInfo();
			setPrefix.setMethod(MainModule.class.getMethod("setPrefix", String.class));
			Parameter[] setPrefixParas = {new Parameter("prefix",true)};
			setPrefix.setMethodParas(setPrefixParas);
			prefix.setSet(setPrefix);
			
			MethodInfo getPrefix = new MethodInfo();
			getPrefix.setMethod(MainModule.class.getMethod("getPrefix", null));
			prefix.setGet(getPrefix);
			mapInfo.addBasicField(prefix);
			
			//namespace
			LeafFieldMap namespace = new LeafFieldMap();
			namespace.setFieldName("namespace");
			MethodInfo setNamespace = new MethodInfo();
			setNamespace.setMethod(MainModule.class.getMethod("setNamespace", String.class));
			Parameter[] setNamespaceParas = {new Parameter("namespace",true)};
			setNamespace.setMethodParas(setNamespaceParas);
			namespace.setSet(setPrefix);
			
			MethodInfo getNamespace = new MethodInfo();
			getNamespace.setMethod(MainModule.class.getMethod("getNamespace", null));
			namespace.setGet(getNamespace);
			mapInfo.addBasicField(namespace);
		}
		else {
			//belongsto
			LeafFieldMap belongsto = new LeafFieldMap();
			belongsto.setFieldName("belongsto");
			belongsto.setElementClass(BelongsTo.class);
			MethodInfo createBelongsto = new MethodInfo();
			createBelongsto.setMethod(SubModule.class.getMethod("createBelongsto", String.class,String.class));
			Parameter[] belongstoPara = {new Parameter("module",true,true),
					new Parameter("prefix",true,false)};
			createBelongsto.setMethodParas(belongstoPara);
		}

		
		//meta info
		//orgnaization
		LeafFieldMap orgnaization = new LeafFieldMap();
		orgnaization.setFieldName("organization");
		MethodInfo setOrg = new MethodInfo();
		setOrg.setMethod(MainModule.class.getMethod("setOrganization", String.class));
		Parameter[] setOrgParas = {new Parameter("organization",true)};
		setOrg.setMethodParas(setOrgParas);
		orgnaization.setSet(setOrg);
		
		MethodInfo getOrg = new MethodInfo();
		getOrg.setMethod(MainModule.class.getMethod("getOrganization", null));
		orgnaization.setGet(getOrg);
		mapInfo.addBasicField(orgnaization);
		
		//contact
		LeafFieldMap contact = new LeafFieldMap();
		contact.setFieldName("contact");
		MethodInfo setContact = new MethodInfo();
		setContact.setMethod(MainModule.class.getMethod("setContact", String.class));
		Parameter[] setContactParas = {new Parameter("contact",true)};
		setContact.setMethodParas(setContactParas);
		contact.setSet(setContact);
		
		MethodInfo getContact = new MethodInfo();
		getContact.setMethod(MainModule.class.getMethod("getContact", null));
		contact.setGet(getContact);
		mapInfo.addBasicField(contact);	
		
		//description
		LeafFieldMap description = new LeafFieldMap();
		description.setFieldName("description");
		MethodInfo setDerscription = new MethodInfo();
		setDerscription.setMethod(MainModule.class.getMethod("setDescription", String.class));
		Parameter[] setDescParas = {new Parameter("description",true)};
		setDerscription.setMethodParas(setDescParas);
		description.setSet(setDerscription);
		
		MethodInfo getDescription = new MethodInfo();
		getDescription.setMethod(MainModule.class.getMethod("getDescription", null));
		description.setGet(getDescription);
		mapInfo.addBasicField(description);	
		//reference
		LeafFieldMap reference = new LeafFieldMap();
		reference.setFieldName("reference");
		MethodInfo setRefer = new MethodInfo();
		setRefer.setMethod(MainModule.class.getMethod("setReference", String.class));
		Parameter[] setReferParas = {new Parameter("reference",true)};
		setRefer.setMethodParas(setReferParas);
		reference.setSet(setRefer);
		
		MethodInfo getRefer = new MethodInfo();
		getRefer.setMethod(MainModule.class.getMethod("getReference", null));
		reference.setGet(getRefer);
		mapInfo.addBasicField(reference);	
		
		//composite fields
		//linkage statements
		//import
		ListFieldMap imp = new ListFieldMap();
		imp.setFieldName("import");
		imp.setElementClass(Import.class);
		MethodInfo createImport = new MethodInfo();
		createImport.setMethod(this.getClass().getMethod("createImport", String.class));
		Parameter[] createImportParas = {new Parameter("module",true,true)};
		createImport.setMethodParas(createImportParas);
		imp.setCreate(createImport);
		mapInfo.addCompositeField(imp);
		//include
		ListFieldMap include = new ListFieldMap();
		include.setFieldName("include");
		include.setElementClass(Include.class);
		MethodInfo createInclude = new MethodInfo();
		createInclude.setMethod(this.getClass().getMethod("createInclude", String.class));
		Parameter[] createIncludeParas = {new Parameter("module",true,true)};
		createInclude.setMethodParas(createIncludeParas);
		include.setCreate(createInclude);
		mapInfo.addCompositeField(include);
		//revision-stmts
		ListFieldMap revision = new ListFieldMap();
		revision.setFieldName("revision");
		revision.setElementClass(Revision.class);
		MethodInfo createRevision = new MethodInfo();
		createRevision.setMethod(this.getClass().getMethod("createRevision", String.class));
		Parameter[] createRevisionParas = {new Parameter("revision",true,true)};
		createRevision.setMethodParas(createRevisionParas);
		revision.setCreate(createRevision);
		mapInfo.addCompositeField(revision);
		// body-stmts
		//extension
		ListFieldMap extension = new ListFieldMap();
		extension.setFieldName("extension");
		extension.setElementClass(Extension.class);
		MethodInfo createExtension = new MethodInfo();
		createExtension.setMethod(this.getClass().getMethod("createExtension", String.class));
		Parameter[] createExtensionParas = {new Parameter("name",true,true)};
		createExtension.setMethodParas(createExtensionParas);
		extension.setCreate(createExtension);
		mapInfo.addCompositeField(extension);
		//feature
		ListFieldMap feature = new ListFieldMap();
		feature.setFieldName("feature");
		feature.setElementClass(Feature.class);
		MethodInfo createFeature = new MethodInfo();
		createFeature.setMethod(this.getClass().getMethod("createFeature", String.class));
		Parameter[] createFeatureParas = {new Parameter("name",true,true)};
		createFeature.setMethodParas(createFeatureParas);
		feature.setCreate(createFeature);
		mapInfo.addCompositeField(feature);
		//identity
		ListFieldMap identity = new ListFieldMap();
		identity.setFieldName("identity");
		identity.setElementClass(Identity.class);
		MethodInfo createIdentity = new MethodInfo();
		createIdentity.setMethod(this.getClass().getMethod("createIdentity", String.class));
		Parameter[] createIdentityParas = {new Parameter("name",true,true)};
		createIdentity.setMethodParas(createIdentityParas);
		identity.setCreate(createIdentity);
		mapInfo.addCompositeField(identity);
		/*
		 * typedefs
		 */
		ListFieldMap typedef = new ListFieldMap();
		typedef.setFieldName("typedef");
		typedef.setElementClass(Typedef.class);
		MethodInfo createTypedef = new MethodInfo();
		createTypedef.setMethod(this.getClass().getMethod("createTypedef", String.class));
		Parameter[] createTypedefParas = {new Parameter("name",true,true)};
		createTypedef.setMethodParas(createTypedefParas);
		typedef.setCreate(createTypedef);
		mapInfo.addCompositeField(typedef);
		

		/*
		 * nodes
		 */
		ListFieldMap node = new ListFieldMap();
		node.setFieldName("node");
		node.setElementClass(Node.class);
		MethodInfo createNode = new MethodInfo();
		createNode.setMethod(MainModule.class.getMethod("createNode", String.class,String.class));
		ArrayList<String> nodeType = new ArrayList<String> (1);
		nodeType.add(YangKeyword.CONTAINER.getKeyword());
		nodeType.add(YangKeyword.LIST.getKeyword());
		nodeType.add(YangKeyword.CHOICE.getKeyword());
		nodeType.add(YangKeyword.LEAF.getKeyword());
		nodeType.add(YangKeyword.LEAFLIST.getKeyword());
		nodeType.add(YangKeyword.ANYXML.getKeyword());
		ArrayList<String> names = new ArrayList<String>(1);
		names.add("configuration");
		names.add("state");
		names.add("operation");
		Parameter[] createNodeparas = {new Parameter("nodeType",nodeType,true),new Parameter("name",true)}; 
		createNode.setMethodParas(createNodeparas);
		node.setCreate(createNode);
		mapInfo.addCompositeField(node);
		/*
		 * uses
		 */
		ListFieldMap uses = new ListFieldMap();
		uses.setFieldName("uses");
		uses.setElementClass(Uses.class);
		MethodInfo createUses = new MethodInfo();
		createUses.setMethod(this.getClass().getMethod("createUses", String.class));
		Parameter[] createUsesParas = {new Parameter("name",true,true)};
		createUses.setMethodParas(createUsesParas);
		uses.setCreate(createUses);
		mapInfo.addCompositeField(uses);
		/*
		 * notification
		 */
		ListFieldMap notification = new ListFieldMap();
		notification.setFieldName("notification");
		notification.setElementClass(Notification.class);
		MethodInfo createNotification = new MethodInfo();
		createNotification.setMethod(this.getClass().getMethod("createNotification", String.class));
		Parameter[] createNotificationParas = {new Parameter("name",true,true)};
		createNotification.setMethodParas(createNotificationParas);
		notification.setCreate(createNotification);
		mapInfo.addCompositeField(notification);
		/*
		 * augment
		 */
		ListFieldMap augment = new ListFieldMap();
		augment.setFieldName("augment");
		augment.setElementClass(Augment.class);
		MethodInfo createAugment = new MethodInfo();
		createAugment.setMethod(this.getClass().getMethod("createAugment", String.class));
		Parameter[] createAugmentParas = {new Parameter("name",true,true)};
		createAugment.setMethodParas(createAugmentParas);
		augment.setCreate(createAugment);
		mapInfo.addCompositeField(augment);
		/*
		 * deviations
		 */
		ListFieldMap deviation = new ListFieldMap();
		deviation.setFieldName("deviation");
		deviation.setElementClass(Deviation.class);
		MethodInfo createDeviation = new MethodInfo();
		createDeviation.setMethod(this.getClass().getMethod("createDeviation", String.class));
		Parameter[] createDeviationParas = {new Parameter("name",true,true)};
		createDeviation.setMethodParas(createDeviationParas);
		deviation.setCreate(createDeviation);
		mapInfo.addCompositeField(deviation);
		
		return mapInfo;
	}

public Node createDataDef(String string, String _Configuration) {
	// TODO Auto-generated method stub
	return null;
}


///**
// * ��ȡ�ڵ��������Ϣ
// * @return
// */
//	public List<NodeDescrInfo> getNodeDescrInfo(){
//		ArrayList<NodeDescrInfo> nodeDesList = new ArrayList<NodeDescrInfo>();
//		for(int i = 0; i < this.getNodesNumber() ; i++){
//			Node tempNode = this.getNode(i);
//			NodeDescrInfo nodeDescrInfo = new NodeDescrInfo(0,tempNode.getName(),"Container","",tempNode.getNativeDescr());
//			nodeDesList.add(nodeDescrInfo);
//			depthErgodic(tempNode,nodeDesList,1);
//		}
//		return nodeDesList;
//	}
//	//��ȱ������нڵ�
//	private void depthErgodic(Node nodeItem, ArrayList<NodeDescrInfo> nodeDesList, int level){
//		if(nodeItem.getSonsNumber() == 0 ){
//			return;
//		}
//		for(int i = 0 ; i < nodeItem.getSonsNumber() ; i++){
//			Node tempNode = nodeItem.getSon(i);
//			String isKey = "";
//			if(tempNode.isKey()){
//				isKey = "key";
//			}
//			NodeDescrInfo nodeDescrInfo = new NodeDescrInfo(level,tempNode.getName(),tempNode.getClass().getSimpleName(),isKey,tempNode.getNativeDescr());
//			nodeDesList.add(nodeDescrInfo);
//			depthErgodic(tempNode,nodeDesList,level+1);
//		}
//	}

}
